#include<iostream>
using namespace std;
typedef long long LL;
const int N = 3e5 + 10;
int n, m;
int a[N];
int q[N];
LL s[N];
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		s[i] = s[i - 1] + a[i];
	}
	int hh = 0, tt = 0;
	LL ans = -1e18;	
	for (int i = 1; i <= n; i++) {
		if (q[hh] + m < i)hh++;
		ans = max(ans, s[i] - s[q[hh]]);
		while (hh <= tt && s[q[tt]] >= s[i])tt--;
		q[++tt] = i;
	}
	cout << ans << endl;
	return 0;
}